import 'package:baby_health_tracker/screen/records.dart';
import 'package:baby_health_tracker/screen/settings.dart';
import 'package:baby_health_tracker/screen/stats.dart';
import 'package:flutter/material.dart';
import 'dashboard.dart';

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {

  int _selectedIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _selectedIndex,
        children: [
          DashboardTab(),
          RecordsTab(),
          StatisticsTab(),
          SettingsTab(),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        onTap: (index){
         setState(() {
           _selectedIndex = index;
         });
        },
        currentIndex: _selectedIndex,
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.dashboard_rounded),label: '首页'),
          BottomNavigationBarItem(icon: Icon(Icons.event_note_rounded),label: '记录'),
          BottomNavigationBarItem(icon: Icon(Icons.insert_chart_rounded),label: '分析'),
          BottomNavigationBarItem(icon: Icon(Icons.settings_rounded),label: '设置'),
        ],

      ),
    );
  }
}

class MainPage extends StatefulWidget {
  const MainPage({super.key});

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  int _currentIndex = 0; // 当前选中的底部导航索引

  // 页面列表 - 每个标签对应的页面
  final List<Widget> _pages = [
    DashboardTab(),
    RecordsTab(),
    StatisticsTab(),
    SettingsTab(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _pages[_currentIndex], // 显示当前页面
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: (index) {
          setState(() {
            _currentIndex = index; // 切换页面
          });
        },
        items: const [
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            label: '首页',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.search),
            label: '搜索',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.favorite),
            label: '收藏',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.person),
            label: '我的',
          ),
        ],
        fixedColor: Theme.of(context).primaryColor,
      ),
    );
  }
}
